<template>
  <div class="know">
    <div class="container-box">
      <div class="page-container">
        <!-- 左侧部分 -->
        <LeftContainer :tree="tree" @emitSel="getSel"></LeftContainer>
        <!-- 右侧部分 -->
        <div class="right-container">
          <div class="screen-container">
            <!-- 搜索框 -->
            <el-form :inline="true"  class="demo-form-inline">
              <el-form-item label="关键字">
                <el-input
                  v-model="input_value"
                  size="small"
                  placeholder="请输入名称/标识符"
                  style="width: 260px; margin-right: 24px"
                  class="seach-input"
                ></el-input>
              </el-form-item>
              <el-form-item>
                <!-- 按钮 -->
                <el-button type="primary" size="small">查询</el-button>
              </el-form-item>
            </el-form>
          </div>

          <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
              <el-button
                type="primary"

                icon="el-icon-plus"
                size="mini"
                @click="handleAdd"
                v-hasPermi="['system:role:add']"
              >新增
              </el-button
              >
              <el-button disabled  size="mini">批量删除</el-button>
            </el-col>
          </el-row>

          <el-table
            v-loading="loading"
            :data="roleList"

            :header-cell-style="{ background: '#F3F5FC' }"

          >
            <el-table-column type="selection"  align="center" width="50"/>
            <!-- <el-table-column label="角色编号" prop="roleId" width="120" /> -->
            <el-table-column label="序号" align="center" width="50">
              <template slot-scope="scop">
                {{ scop.$index + 1 }}
              </template>
            </el-table-column>
            <el-table-column label="知识名称" prop="tagName"/>
            <el-table-column
              label="事件分类"
              prop="dataSrcPlace"
              :show-overflow-tooltip="true"
               width="90"
            />
            <el-table-column
              label="事件名称"
              prop="dataSrcDept"
              :show-overflow-tooltip="true"
               width="120"
            />


            <el-table-column label="创建时间"  prop="dataCreateTime"/>
            <el-table-column label="更新时间"   prop="dataUpdateTime">
            </el-table-column>
            <el-table-column label="启用状态" prop="groupType">
              <template slot-scope="scope">
                <el-switch
                  v-model="scope.row.groupType"
                  active-value="1"
                  inactive-value="2"
                  @change="handleStatusChange(scope.row)"
                ></el-switch>
              </template>
            </el-table-column>
            <el-table-column
              label="操作"
              align="center"
              class-name="small-padding fixed-width"
              width="150"
            >
                <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"

                  icon="el-icon-edit"
                  @click="handleUpdate(scope.row)"
                >修改
                </el-button
                >

                <el-button
                  v-if="scope.row.parentId != 0"
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleDelete(scope.row)"
                >删除
                </el-button
                >
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="total > 0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
          <el-dialog
            title="新增"
            :visible.sync="dialogFormVisible"
            width="1000px"
            :modal-append-to-body="false"
            :close-on-click-modal="false"
            class="dia-style"
          >
            <div style="padding: 0 20px 20px 0">
              <ZskForm></ZskForm>
            </div>
            <!-- 底部 -->
            <div slot="footer">
              <el-button @click="dialogFormVisible = false">取 消</el-button>
              <el-button type="primary" @click="dialogFormVisible = false"
              >保 存
              </el-button
              >
            </div>
          </el-dialog>


          <el-dialog
            title="修改"
            :visible.sync="dialogUpdteFormVisible"
            width="1000px"
            :modal-append-to-body="false"
            :close-on-click-modal="false"
            class="dia-style"
          >
            <div style="padding: 0 20px 20px 0">
              <updateZskForm></updateZskForm>
            </div>
            <!-- 底部 -->
            <div slot="footer">
              <el-button @click="dialogUpdteFormVisible = false">取 消</el-button>
              <el-button type="primary" @click="dialogUpdteFormVisible = false"
              >保 存
              </el-button
              >
            </div>
          </el-dialog>

        </div>
      </div>
      <!-- 提示框 -->
    </div>
  </div>
</template>

<script>
import LeftContainer from '@/components/trees/LeftContainer.vue'
import RightContainer from '@/components/trees/RightContainer.vue'
import axios from 'axios'
import ZskForm from '@/components/Common/ZskForm'
import updateZskForm from '@/components/Common/updateZskForm'

export default {
  components: { ZskForm, updateZskForm,LeftContainer, RightContainer },
  data() {
    return {

      dialogFormVisible: false,
      dialogUpdteFormVisible:false,
      // 总条数
      total: 14,
      //是否在加载
      loading: true,
      //   搜索框的值
      input_value: '',
      //   子组件传输的值
      checkList: [],
      // 角色表格数据
      roleList: [],
      //   树形结构的值
      tree: [
        {
          title: '事件分类',
          name: 'jb',
          id: 2,
          showchild:true,
          child: [
            {
              title: '用户违规',
              num: 4,
              id: 4
            },
            {
              title: '运维异常',
              num: 2,
              id: 5
            },
            {
              title: '网络攻击',
              num: 0,
              id: 6
            },
            {
              title: '基础设施故障',
              num: 0,
              id: 6
            }
          ]
        }
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roleName: undefined,
        roleKey: undefined,
        status: undefined
      }
    }
  },
  methods: {
    // 获取子组件传参
    getSel(data) {
      this.checkList = data
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.dialogFormVisible = true
      this.title = '添加角色'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
     this.dialogUpdteFormVisible=true;
        this.title = '添加角色'
    },
  handleStatusChange(row) {
      let text = row.status === "1" ? "启用" : "停用";
      this.$modal.confirm('确认要' + text   + '吗？').then(function() {
        return changeUserStatus(row.userId, row.status);
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function() {
        row.status = row.status === "0" ? "1" : "0";
      });
    },
    /** 查询角色列表 */
    getList() {
      this.loading = true
      axios.get('zsk.json').then((res) => {
        this.roleList = res.data.data.list
        this.total = res.data.data.total
        this.loading = false
        console.log(this.roleList)
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal
        .confirm('是否确认删除此数据项？')
        .then(function() {
          // return delDept(row.deptId);
        })
        .then(() => {
          this.getList()
          this.$modal.msgSuccess('删除成功')
        })
        .catch(() => {
        })
    }
  },
  mounted() {
    this.getList()
  }
}
</script>

<style lang="scss" scoped>
.know{
  height: 100%;
}
.screen-container{
  padding:0 0 20px ;
}
.page-container {
  height: 100%;

  .right-container {
    height: 100%;

    .el-table {
      overflow: auto;
    }
  }
}
.pagination-container{
  padding: 0 !important;
}
</style>
